<template>
  <div class="container">
    <div id="chart-box" style="width: 800px; height: 360px"></div>
  </div>
</template>

<script setup>
import * as echarts from 'echarts/core';
import { GridComponent } from 'echarts/components';
import { LineChart } from 'echarts/charts';
import { UniversalTransition } from 'echarts/features';
import { CanvasRenderer } from 'echarts/renderers';
import { onMounted } from 'vue';

echarts.use([GridComponent, LineChart, CanvasRenderer, UniversalTransition]);

onMounted(() => {
  initChart(1, 420, 60);
});

const initChart = (min, max, interval) => {
  const chartDom = document.getElementById('chart-box');
  const myChart = echarts.init(chartDom);

  const option = {
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value',
      // scale: true, // 脱离 0 值比例
      min: min,
      max: max,
      interval: interval
    },
    series: [
      {
        data: [150, 230, 224, 218, 135, 147, 260],
        type: 'line'
      }
    ]
  };

  myChart.setOption(option);
};
</script>

<style lang="less" scoped></style>
